package com.zx.common;

import java.lang.reflect.Field;
import java.util.Arrays;

import com.zx.ziroom.Room;

public class BeanUtil {
	
	/**
	 * @Title: 将Java对象转为数组，顺序与实体类中field由上至下
	 * @param obj
	 * @param clazz
	 * @return
	 * @throws Exception
	 * @Description: TODO
	 * @date: 2017年12月6日下午11:10:22
	 */
	public static Object[] beanToString(Object obj, Class<?> clazz) throws Exception {
		Field[] fields = clazz.getDeclaredFields();
		Object[] os = new Object[fields.length];
		
		for (int i = 0; i < fields.length; i++) {
			fields[i].setAccessible(true);
			os[i] = fields[i].get(obj);
		}
		
		return os;
	}
	
	public static void main(String[] args) {
		Room room = new Room(null, "1", "2", "3", "4", "5", "6", "7", "8", "9");
		Object[] beanToString = null;
		try {
			beanToString = beanToString(room, Room.class);
		} catch (Exception e) {
			e.printStackTrace();
		}
		System.out.println(Arrays.toString(beanToString));
	}
}
